import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:smart_ai_dart/pages/edit_profile_page/controller.dart';

class EditProfilePage extends GetView<EditProfileController> {
  const EditProfilePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('edit_profile'.tr),
        actions: [
          TextButton(
            onPressed: controller.saveProfile,
            child: Text('save'.tr),
          ),
        ],
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              _buildAvatarSection(),
              const SizedBox(height: 24),
              _buildProfileForm(),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildAvatarSection() {
    return Obx(() => GestureDetector(
          onTap: controller.changeAvatar,
          child: Column(
            children: [
              CircleAvatar(
                radius: 32,
                backgroundImage: controller.avatarUrl.value.isNotEmpty
                    ? NetworkImage(controller.avatarUrl.value)
                    : const AssetImage('assets/images/default_avatar.png')
                        as ImageProvider,
              ),
              const SizedBox(height: 12),
              Text(
                'change_avatar'.tr,
                style: const TextStyle(
                  color: Colors.blue,
                  fontSize: 16,
                ),
              ),
            ],
          ),
        ));
  }

  Widget _buildProfileForm() {
    return Column(
      children: [
        TextField(
          controller: controller.nicknameController,
          decoration: InputDecoration(
            labelText: 'nickname'.tr,
            border: const OutlineInputBorder(),
            prefixIcon: const Icon(Icons.person),
          ),
        ),
        const SizedBox(height: 16),
        TextField(
          controller: controller.emailController,
          decoration: InputDecoration(
            labelText: 'email'.tr,
            border: const OutlineInputBorder(),
            prefixIcon: const Icon(Icons.email),
          ),
          keyboardType: TextInputType.emailAddress,
        ),
        const SizedBox(height: 16),
        TextField(
          controller: controller.phoneController,
          decoration: InputDecoration(
            labelText: 'phone'.tr,
            border: const OutlineInputBorder(),
            prefixIcon: const Icon(Icons.phone),
          ),
          keyboardType: TextInputType.phone,
        ),
      ],
    );
  }
}
